package com.cskaoyan.service;

import com.cskaoyan.bean.entity.Coupon;
import com.cskaoyan.bean.entity.CouponExample;
import com.cskaoyan.mapper.CouponMapper;
import com.cskaoyan.utils.LimitListSizeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CouponServiceImpl implements  CouponService {

    @Autowired
    CouponMapper couponMapper;

    @Override
    public List<Coupon> getAllEnableCoupons() {
        CouponExample couponExample = new CouponExample();
        CouponExample.Criteria couponExampleCriteria = couponExample.createCriteria();
        // 获取所有可用的消费券 即 status是0
        couponExampleCriteria.andStatusEqualTo(Short.parseShort("0"));
        List<Coupon> couponList = couponMapper.selectByExample(couponExample);
        return LimitListSizeUtil.limitSize(couponList);
    }
}
